//
//  HMMineCell.m
//  欢乐美食
//
//  Created by MacOS on 15/7/11.
//  Copyright (c) 2015年 遇水. All rights reserved.
//

#import "HMMineCell.h"
#import "HMMineItem.h"
#import "HMMineArrowItem.h"

@interface HMMineCell()

@property (nonatomic, strong) UIImageView *arrowView;


@property (nonatomic, strong) UIView *seperator;

@end

@implementation HMMineCell


#pragma 懒加载
- (UIImageView *)arrowView
{
    if (_arrowView == nil) {
        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_cell_rightArrow"]];
    }
    return _arrowView;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"mineCell";
    HMMineCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[HMMineCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    return cell;
}

#pragma 添加分割线
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor grayColor];
        self.seperator = view;
        [self addSubview:view];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat seperatorX = 0;
    CGFloat seperatorW = [UIScreen mainScreen].bounds.size.width;
    CGFloat seperatorH = 1;
    CGFloat seperatorY = self.frame.size.height - seperatorH;
    
    self.seperator.frame = CGRectMake(seperatorX, seperatorY, seperatorW, seperatorH);
    
}

- (void)setItem:(HMMineItem *)item
{
    _item = item;
    
    self.imageView.image = [UIImage imageNamed:item.icon];
    self.textLabel.text = item.title;
    self.detailTextLabel.text = item.subtitle;
    
    if ([item isKindOfClass:[HMMineArrowItem class]]) {
        self.accessoryView = self.arrowView;
    } else { // 解决布局重复利用的错乱问题
        self.accessoryView = nil;
    }
    
}

- (void)setHiddenSeperator:(BOOL)hiddenSeperator
{
    self.seperator.hidden = hiddenSeperator;
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
